package org.intrasearch.spider;

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;

import java.io.File;
import java.net.MalformedURLException;

/**
 * PATISDG 11.11.2009
 */
public class VirtualFiles
{
    public static VirtualFile createFromPathOrUrl(String pathOrUrl, String user, String password)
    {
        if (pathOrUrl.startsWith("smb://"))
        {
            try
            {
                NtlmPasswordAuthentication ntlmPasswordAuthentication = null;
                if (user != null)
                {
                    ntlmPasswordAuthentication = new NtlmPasswordAuthentication(user + ":" + password);
                }
                return new VirtualFileSmbImpl(new SmbFile(pathOrUrl, ntlmPasswordAuthentication));
            }
            catch (MalformedURLException e)
            {
                throw new RuntimeException(e);
            }
        }
        return new VirtualFileFileImpl(new File(pathOrUrl));
    }
}
